package DAO.impl;

import DAO.BaseDao;
import DAO.ItemsDAO;
import bean.Items;

import java.sql.Connection;
import java.util.List;

/**
 * @author 栋
 * @date 2022/11/8
 * @description
 */
public class ItemsDAOImpl extends BaseDao<Items>implements ItemsDAO {
    @Override
    public int add_item(Connection conn, Items item) {
        String sql="insert into items(item_id,item_name,item_type,item_count,item_price,item_introduce,item_img,Ower_id,method,app_date,app_time,is_qualified,admin_id,audit_date,audit_time) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        return update(conn,sql,item.getItem_id(),item.getItem_name(),item.getItem_type(),item.getItem_count(),item.getItem_price(),item.getItem_introduce(),item.getItem_img(),item.getOwer_id(),item.getMethod(),item.getApp_date(),item.getApp_time(),item.getIs_qualified(),item.getAdmin_id(),item.getAudit_date(),item.getAudit_time());
    }

    @Override
    public int delet_item(Connection conn, String item_id) {
        String sql="delete from items where item_id = ?";
        return update(conn,sql,item_id);
    }

    @Override
    public int update_item(Connection conn, Items item) {
        String sql="update items set item_name=?,item_type=?,item_count=?,item_price=?,item_introduce=?,item_img=?,Ower_id=?,method=?,app_date=?,app_time=?,is_qualified=?,admin_id=?,audit_date=?,audit_time=? where item_id=?";
        return update(conn,sql,item.getItem_name(),item.getItem_type(),item.getItem_count(),item.getItem_price(),item.getItem_introduce(),item.getItem_img(),item.getOwer_id(),item.getMethod(),item.getApp_date(),item.getApp_time(),item.getIs_qualified(),item.getAdmin_id(),item.getAudit_date(),item.getAudit_time(),item.getItem_id());

    }

    @Override
    public List<Items> get_all_items(Connection conn) {
        String sql="select * from items";
        return getForList(conn,sql);
    }

    @Override
    public List<Items> getItemsByOwer(Connection conn, String user_id) {
        String sql="select * from items where Ower_id=?";
        return getForList(conn,sql,user_id);
    }

    @Override
    public Items getItemById(Connection conn, String item_id) {
        String sql="select * from items where item_id=?";
        return getInstance(conn,sql,item_id);
    }

    @Override
    public List<Items> getQualifiedItems(Connection conn) {
        String sql ="select * from items where is_qualified=?";
        return getForList(conn,sql,"是");
    }

    @Override
    public List<Items> getItemsByType(Connection conn, int type) {
        String sql="select * from items where item_type=? and is_qualified=?";
        return getForList(conn,sql,type,"是");
    }

    @Override
    public List<Items> getItemsBySearch(Connection conn, String name) {
        String sql="select * from items where item_name like ?";
        return getForList(conn,sql,name);
    }

    @Override
    public List<Items> getShenHeItems(Connection conn) {
        String sql="select * from items where isNull(is_qualified)";
        return getForList(conn,sql);

    }
}
